import { Module } from '@nestjs/common';
import { DynamiclayerService } from './dynamiclayer.service';
import { DynamiclayerController } from './dynamiclayer.controller';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname, join } from 'path';
import { Dynamiclayer } from './entities/dynamiclayer.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as path from 'path';
@Module({
  imports: [
    MulterModule.register({
      storage: diskStorage({
        destination: function (req, fileName, callback) {
          try {
            callback(
              null,
              path.resolve(process.env.FILE_PATH + '/dynamiclayer'),
            );
          } catch (error) {
            console.error('Error in setting dynamiclayer destination:', error);
          }
        },
        filename: (_, file, callback) => {
          const fileName = `${
            new Date().getTime() + extname(file.originalname)
          }`;
          return callback(null, fileName);
        },
      }),
    }),
    TypeOrmModule.forFeature([Dynamiclayer]),
  ],
  controllers: [DynamiclayerController],
  providers: [DynamiclayerService],
  exports: [DynamiclayerService],
})
export class DynamiclayerModule {}
